// pages/bookRoom/bookRoom.js
const dorms= {
  '南校区': ['C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9', 'C10', 'C11', 'C12', 'C13', 'C14', 'C15', 'C16', 'C17'],
    };

Page({
  

  data: {
    
    columns: [
      {
        values: Object.keys(dorms),
        className: 'column1'
      },
      {
        values: dorms['南校区'],
        className: 'column2',
        defaultIndex: 2
      }
    ],
    multiArray: [['南校区', '北校区'], ['C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9', 'C10', 'C11', 'C12', 'C13', 'C14', 'C15', 'C16', 'C17'],[]],
    startTime: "00:00",
    endTime: "00:00",
    buildingArray:  
      ['C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9', 'C10', 'C11', 'C12', 'C13', 'C14', 'C15', 'C16', 'C17'],
    objectMultiArray: [
      [
        {
          id: 0,
          name: '南校区'
        },
      ], [
        {
          id: 0,
          name: 'C1'
        },
        {
          id: 1,
          name: 'C2'
        },
        {
          id: 2,
          name: 'C3'
        },
        {
          id: 3,
          name: 'C4'
        },
        {
          id: 4,
          name: 'C5'
        },
        {
          id: 5,
          name: 'C6'
        },
        {
          id: 6,
          name: 'C7'
        },
        {
          id: 7,
          name: 'C8'
        },
        {
          id: 8,
          name: 'C9'
        },
        {
          id: 9,
          name: 'C10'
        },
        {
          id: 10,
          name: 'C11'
        },
        {
          id: 11,
          name: 'C2'
        },
        {
          id: 12,
          name: 'C13'
        },
        {
          id: 13,
          name: 'C14'
        },
        {
          id: 14,
          name: 'C15'
        },
        {
          id: 15,
          name: 'C16'
        },
        {
          id: 16,
          name: 'C17'
        }
      ],
      [


      ]
    ],
    array:['上午1 2节','上午3 4节','下午5 6节','下午7 8节','晚上9 10 11节','整个上午','整个下午','整个晚上'],
    objectArray: [
      {
        id: 0,
        name: '上午1 2节'
      },
      {
        id: 1,
        name: '上午3 4节'
      },
      {
        id: 2,
        name: '下午5 6节'
      },
      {
        id: 3,
        name: '下午7 8节'
      },
      {
        id: 4,
        name: '晚上9 10 11节'
      },
      {
        id: 5,
        name: '整个上午'
      },
      {
        id: 6,
        name: '整个下午'
      },
      {
        id: 7,
        name: '整个晚上'
      },
    ],
    multiIndex: [0],
    date:new Date().getFullYear()+"-"+(new Date().getMonth()+1)+"-"+new Date().getDate(),
    index:0,
    hidden: 'none',
    hidden1: 'true',
  },


  onChange(event) {
    const { picker, value, index } = event.detail;
    picker.setColumnValues(1, citys[value[0]]);
  },

  onReady: function () {

  },


  bindMultiPickerChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      multiIndex: e.detail.value
    })
  },

  bindMultiPickerColumnChange: function (e) {
    console.log('修改的列为', e.detail.column, '，值为', e.detail.value);
    var data = {
      multiArray: this.data.multiArray,
      multiIndex: this.data.multiIndex 
    };
    data.multiIndex[e.detail.column] = e.detail.value;
    switch (e.detail.column) {
      case 0:
        switch (data.multiIndex[0]) {
          case 0:
            data.multiArray[1] = ['C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9', 'C10', 'C11', 'C12', 'C13', 'C14', 'C15', 'C16', 'C17'];
            data.multiArray[2] = [];
            break;
          case 1:
            data.multiArray[1] = ['北区', '西区', '东区'];
            data.multiArray[2] = ['北2', '北3', '北11', '北12', '北13', '北14'];
            break;
        }
        data.multiIndex[1] = 0;
        data.multiIndex[2] = 0;
        break;
      case 1:
        switch (data.multiIndex[0]) {
          case 0:
             data.multiArray[2] =[];
             break;
          case 1:
            switch (data.multiIndex[1]) {
              case 0:
                data.multiArray[2] = ['北2', '北3', '北8', '北10', '北11', '北12', '北13', '北14', '北15', '北16', '北17',];
                break;
              case 1:
                data.multiArray[2] = ['西二区研1学生宿舍', '西二区研2学生宿舍', '西二区研5学生宿舍','西7','西17','西18','西19'  ];
                break;
              case 2:
                data.multiArray[2] = ['东6', '东11'];
                break;
            }
            break;
        }
        data.multiIndex[2] = 0;
        console.log(data.multiIndex);
        break;
    }
    this.setData(data);
  },

  bindDateChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date: e.detail.value
    })
  },
  
  bindPickerChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      index: e.detail.value
    })
  },


  confirmReserve: function (e) {
    this.setData({
      hidden: 'true',
      hidden1: 'none',
    })
    var roomId = String(this.data.multiIndex[1]+1)+String(this.data.floor)
    var startTime =this.data.startTime+":00"
    var endTime = this.data.endTime + ":00"
    var defaultApply=0
    var userId=wx.getStorageSync('openid')
    wx.request({
      url: 'http://localhost:8080/record/addRecord',
      method:'POST',
      data:{
        roomId:roomId,
        time: this.data.date,
        begin: startTime,
        end: endTime,
        reason: this.data.reason,
        isApply: defaultApply,
        userId: userId
      },
      success(res){
        console.log(res.data)
      }
    })
  },


  formSubmit(e) {

    console.log('form发生了submit事件，携带数据为：', e.detail.value)
  },


  startTime: function (e) {
    this.setData({
      startTime: e.detail.value
    })
  },

  endTime: function (e) {
    this.setData({
      endTime: e.detail.value
    })
  },

  getFloor:function(event){
    // event.detail 为当前输入的值
    console.log(event.detail);
    //存入floor
    this.setData({
      floor:event.detail,
    })
  },

  getReason:function(event){
    console.log(event.detail.value);
    //存入reason
    this.setData({
      reason: event.detail.value
    })
  }

})